<template>
    <rx-dialog @handOk="onOk" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <rx-monaco-editor ref="javaCode"
                                  v-model="tabScript"
                                  language="javascript">
                    <template v-slot:monacoeditor>
                        <a-dropdown>
                            <a-menu slot="overlay">
                                <a-menu-item v-for="item in treeDataList" :key="item.key" @click="insert(item.key,'user')">
                                    {{item.title}}
                                </a-menu-item>
                            </a-menu>
                            <a-button style="margin-right: 8px">{{i18n('insertContext', '插入上下文')}}<a-icon type="down"/></a-button>
                        </a-dropdown>
                        <a-dropdown v- v-if="paramConfig.length>0">
                            <a-menu slot="overlay">
                                <a-menu-item v-for="item in paramConfig" @click="insert(item.value,'params')">
                                    {{item.label}}
                                </a-menu-item>
                            </a-menu>
                            <a-button style="margin-right: 8px">传入参数<a-icon type="down"/></a-button>
                        </a-dropdown>
                    </template>
                </rx-monaco-editor>
            </div>
        </rx-layout>
    </rx-dialog>
</template>

<script>
import {Util, RxMonacoEditor,RxCommonScript} from "@lowcode/jpaas-common-lib";
export default {
    name: "TabBtnShow",
    components: {
        RxMonacoEditor,
        RxCommonScript
    },
    props: {
        layerid: {
            type: String,
            default: ""
        },
        destroy: {
            type: Function
        },
        paramConfig:{
            type:Array,
            default: []
        },
        tabScript:{
            type: String,
            default:''
        }
    },
    data(){
        return{
            treeDataList:[
                {title: this.i18n('btnScript.userId', '当前用户ID'), key: "userId"},
                {title: this.i18n('btnScript.account', '当前用户账号'), key: "account"},
                {title: this.i18n('btnScript.userName', '当前用户名称'), key: "fullName"},
                {title: this.i18n('btnScript.deptId', '当前用户部门ID'), key: "deptId"},
                {title: this.i18n('btnScript.deptName', '当前用户部门名称'), key: "deptName"},
                {title: this.i18n('btnScript.companyId', '当前用户公司ID'), key: "companyId"},
            ],
        }
    },
    created(){
    },
    methods:{
        i18n(name, text, key) {
            return this.$ti18(name, text, "formPermiss", key);
        },
        insert(value,type){
            this.insertJavaCode(type+'.'+value);
        },
        insertJavaCode(text) {
            this.$refs.javaCode.insertContent(text);
        },
        onOk(){
            Util.closeWindow(this,"ok",this.tabScript);
        },
        cancel(){
            Util.closeWindow(this,"cancel");
        },
    }
}
</script>

<style scoped>

</style>